<!--
  DeviceHive Admin Console templates

  Copyright (C) 2016 DataArt

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at
 
      http://www.apache.org/licenses/LICENSE-2.0
 
  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

-->  
<!DOCTYPE html>
<html>
<head>
    <title>DeviceHive Web Admin</title>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootswatch/3.3.7/yeti/bootstrap.min.css">
    <link rel="stylesheet" href="css/style-custom.css">
    <link rel="stylesheet" type="text/css" href="scripts/libs/enjoyhint/enjoyhint.css">

    <link href="//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.4.0/css/font-awesome.min.css" rel="stylesheet">
    <!--[if IE]>
    <![endif]-->

    <link rel="stylesheet" type="text/css" href="//cdnjs.cloudflare.com/ajax/libs/jquery-ui-timepicker-addon/1.4.5/jquery-ui-timepicker-addon.min.css">
    <link rel="stylesheet" type="text/css" href="//code.jquery.com/ui/1.11.4/themes/flick/jquery-ui.css">


    <!-- libs -->
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
    <script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.3.3/underscore-min.js"></script>
    <script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/backbone.js/0.9.2/backbone-min.js"></script>
    <script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/backbone.marionette/0.10.0/backbone.marionette.min.js"></script>

    <!-- ui -->
    <script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script>
    <script src="//cdnjs.cloudflare.com/ajax/libs/jquery-ui-timepicker-addon/1.4.5/jquery-ui-timepicker-addon.min.js" type="text/javascript"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

    <!-- backbone extensions -->
    <script type="text/javascript" src="scripts/libs/backbone.extensions.js"></script>

    <!-- functions -->
    <script type="text/javascript" src="scripts/libs/date.format.js"></script>
    <script type="text/javascript" src="scripts/libs/json2.js"></script>
    <script type="text/javascript" src="scripts/libs/funcs.js"></script>

    <!-- asynch support -->
    <script type="text/javascript" src="scripts/libs/backbone.templates.js"></script>
    <script type="text/javascript" src="scripts/models/AuthModel.js"></script>


    <!-- bootstrap -->
    <script type="text/javascript" src="scripts/libs/enjoyhint/enjoyhint.js"></script>
    <script type="text/javascript" src="scripts/libs/jwt-decode-master/build/jwt-decode.min.js"></script>
    <script type="text/javascript" src="scripts/app/application.js"></script>

    <!-- models -->
    <script type="text/javascript" src="scripts/models/MenuItem.js"></script>
    <script type="text/javascript" src="scripts/models/TimeFilters.js"></script>
    <script type="text/javascript" src="scripts/models/enums.js"></script>
    <script type="text/javascript" src="scripts/models/Network.js"></script>
    <script type="text/javascript" src="scripts/models/DeviceType.js"></script>
    <script type="text/javascript" src="scripts/models/User.js"></script>
    <script type="text/javascript" src="scripts/models/UserInNetwork.js"></script>
    <script type="text/javascript" src="scripts/models/UserInDeviceType.js"></script>
    <script type="text/javascript" src="scripts/models/Device.js"></script>
    <script type="text/javascript" src="scripts/models/Command.js"></script>
    <script type="text/javascript" src="scripts/models/Notification.js"></script>
    <script type="text/javascript" src="scripts/models/JwtToken.js"></script>
    <!-- views -->
    <script type="text/javascript" src="scripts/views/Menu.js"></script>

    <script type="text/javascript" src="scripts/views/Login.js"></script>
    <script type="text/javascript" src="scripts/views/AuthHeader.js"></script>

    <script type="text/javascript" src="scripts/views/AppendUserToNetworks.js"></script>
    <script type="text/javascript" src="scripts/views/AppendUserToDeviceTypes.js"></script>
    <script type="text/javascript" src="scripts/views/UserCreateEdit.js"></script>
    <script type="text/javascript" src="scripts/views/UserNetworks.js"></script>
    <script type="text/javascript" src="scripts/views/UserDeviceTypes.js"></script>
    <script type="text/javascript" src="scripts/views/Users.js"></script>
    <script type="text/javascript" src="scripts/views/Networks.js"></script>
    <script type="text/javascript" src="scripts/views/DeviceTypes.js"></script>
    <script type="text/javascript" src="scripts/views/Devices.js"></script>
    <script type="text/javascript" src="scripts/views/Device.js"></script>
    <script type="text/javascript" src="scripts/views/DevicePanels.js"></script>
    <script type="text/javascript" src="scripts/views/Commands.js"></script>
    <script type="text/javascript" src="scripts/views/Notifications.js"></script>
    <script type="text/javascript" src="scripts/views/TimeFilters.js"></script>
    <script type="text/javascript" src="scripts/views/ExpirationTimeSelector.js"></script>
    <script type="text/javascript" src="scripts/views/JwtToken.js"></script>

    <!-- modules -->
    <script type="text/javascript" src="scripts/modules/notifications.js"></script>
    <script type="text/javascript" src="scripts/modules/navigation.js"></script>
    <script type="text/javascript" src="scripts/modules/users.js"></script>
    <script type="text/javascript" src="scripts/modules/networks.js"></script>
    <script type="text/javascript" src="scripts/modules/deviceTypes.js"></script>
    <script type="text/javascript" src="scripts/modules/devices.js"></script>
    <script type="text/javascript" src="scripts/modules/login.js"></script>
    <script type="text/javascript" src="scripts/modules/jwtToken.js"></script>

    <!-- config -->
    <script type="text/javascript" src="scripts/config.js"></script>

</head>
<body>

<script type="text/javascript">
    var idleTime = app.config.sessionLifeTime;
    $(document).ready(function() {
        $("#error-empty-page").show();
        app.addRegions({
                menuArea: "#menu-area",
                topWorkArea: "#top-work-area",
                bottomWorkArea: "#bottom-work-area",
                statusArea: "#status-area"
            });

        // see config in scripts/config.js
        app.start(app.config);

        //Increment the idle time counter every minute.
        setInterval(timerDecrement, 60000); // 1 minute

        //Zero the idle timer on mouse movement.
        $(this).click(function () {
            idleTime = app.config.sessionLifeTime;
        });
    });

    function timerDecrement() {
        idleTime = idleTime - 1;
        if (idleTime < (Math.floor(app.config.sessionLifeTimeRatio * app.config.sessionLifeTime)) && localStorage.deviceHiveToken) {
            idleTime = app.config.sessionLifeTime;
            alert("Your session has expired");
            var redirectUrl = app.f.prepareAbsolutePath(app.config.sessionExpiredRedirectUrl);
            //cleaning tokens in local storage
            localStorage.clear();
            localStorage.introReviewed = true;
            localStorage.lastActivity = (new Date()).valueOf();
            location.href = redirectUrl;
        }
    }
</script>

<div id="app-wrapper" class="container">
    <div id="menu-area"></div>
    <div id="status-area"></div>
    <div id="top-work-area"></div>
    <div id="bottom-work-area"></div>
    <div id="error-empty-page">
        <h1>Oops! Something went wrong on server!</h1>
    </div>
</div>
</body>
</html>
